import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default {
  state: {
    userInfo: {},
    editableTabsValue: 'Index',
    editableTabs: [{  // 默认展示首页
      title: '首页',
      name: 'Index',
    }],
    // 菜单列表
    menuList: [],
    // 权限列表
    permList: [],
    // 有路由
    hasRoutes: false,
  },
  // 事件回调
  mutations: {
    // 保存左侧菜单组件
    setMenuList(state, menus) {
      state.menuList = menus
    },
    // 保存权限
    setPermList(state, perms) {
      state.permList = perms
    },
    // 设置路由状态
    changeRouteStatus(state, hasRoutes) {
      state.hasRoutes = hasRoutes
    },

    // 添加标签页,当点击导航栏的时候进行标签导航的添加
    addTab(state, tab) {
      let index = state.editableTabs.findIndex(e => e.name === tab.name)

      if (index === -1) {
        state.editableTabs.push({
          title: tab.title,
          name: tab.name,
        });
      }
      state.editableTabsValue = tab.name;
    },

    // 重置。。
    resetState: (state) => {
      state.editableTabsValue = 'Index';
      state.editableTabs = [{
        title: '首页',
        name: 'Index',
      }];
      state.menuList = [];
      state.permList = [];
      state.hasRoutes = false;
    },

    setUserInfo: (state, userInfo)=> {
      state.userInfo = userInfo;
    }
  },

  // 异步的mutations，并非直接变更状态。
  actions: {},
  getters:{
    getUserInfo(state){
      console.log("=====>");
      console.log(state.userInfo);
      return state.userInfo
    }
  }
}
